/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.avaliacao.model.dao;

import br.com.avaliacao.model.entities.Criterio;
import br.com.avaliacao.utils.HibernateUtil;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Maicon
 */
public class CriterioDAO implements CRUD<Criterio> {

    @Override
    public boolean inserir(Criterio obj) {
        Session s = HibernateUtil.getSessao().openSession();
        Transaction t = s.beginTransaction();
        s.save(obj);
        t.commit();
        return true;
    }

    @Override
    public boolean atualizar(Criterio obj) {
        Session s = HibernateUtil.getSessao().openSession();
        Transaction t = s.beginTransaction();
        s.update(obj);
        t.commit();
        return true;
    }

    @Override
    public boolean excluir(Criterio obj) {
        Session s = HibernateUtil.getSessao().openSession();
        Transaction t = s.beginTransaction();
        s.delete(obj);
        t.commit();
        return true;
    }

    @Override
    public Criterio consultar(int id) {
        Session s = HibernateUtil.getSessao().openSession();
        return (Criterio) s.load(Criterio.class, id);
    }
    
    @Override
    public List<Criterio> retLista() {
        Session s = HibernateUtil.getSessao().openSession();
        Transaction t = s.beginTransaction();
        List lista = s.createQuery("from Criterio").list();
        t.commit();
        return lista;
    }

}
